package com.atguigu.srb.core.service.impl;

import com.atguigu.srb.core.mapper.UserInfoMapper;
import com.atguigu.srb.core.pojo.entity.TransFlow;
import com.atguigu.srb.core.mapper.TransFlowMapper;
import com.atguigu.srb.core.pojo.entity.UserInfo;
import com.atguigu.srb.core.pojo.vo.TransFlowVO;
import com.atguigu.srb.core.service.TransFlowService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 交易流水表 服务实现类
 * </p>
 *
 * @author LiLi
 * @since 2021-09-23
 */
@Service
public class TransFlowServiceImpl extends ServiceImpl<TransFlowMapper, TransFlow> implements TransFlowService {
    @Autowired
    UserInfoMapper userInfoMapper;
    @Override
    public void saveTransFlow(TransFlowVO transFlowVO) {
        //获取用户基本信息
        QueryWrapper<UserInfo> userInfoQueryWrapper = new QueryWrapper<>();
        userInfoQueryWrapper.eq("bind_code",transFlowVO.getBindCode());
        UserInfo userInfo = userInfoMapper.selectOne(userInfoQueryWrapper);

        //存储交易流水数据
        TransFlow transFlow = new TransFlow();
        transFlow.setUserId(userInfo.getId());
        transFlow.setUserName(userInfo.getName());
        transFlow.setTransNo(transFlowVO.getAgentBillNo());
        transFlow.setTransType(transFlowVO.getTransTypeEnum().getTransType());
        transFlow.setTransTypeName(transFlowVO.getTransTypeEnum().getTransTypeName());
        transFlow.setTransAmount(transFlowVO.getAmount());
        transFlow.setMemo(transFlowVO.getMemo());
        baseMapper.insert(transFlow);

    }

    @Override
    public boolean isSaveTransFlow(String agentBillNo) {
        boolean b= false;
        QueryWrapper<TransFlow> transFlowQueryWrapper = new QueryWrapper<>();
        transFlowQueryWrapper.eq("trans_no",agentBillNo);
        Integer integer = baseMapper.selectCount(transFlowQueryWrapper);
        if(integer<=0){
            b=true;
        }
        return false;
    }
}
